﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using CMS.BaseEntity;
using CMS.DataAccess;

namespace ElectronicSelling.DataAccess
{
    public class HomeProductAccess
    {
        public static DataTable GetMostViewed()
        {
            DataTable dt = DataAccess.ExeStoredNonToDataTable("usp_ProductSelectMostViewed");
            return dt;
        }

        public static DataTable GetNewProduct()
        {
            DataTable dt = DataAccess.ExeStoredNonToDataTable("usp_ProductSelectNew");
            return dt;
        }

        public static DataTable GetNewProductList()
        {
            DataTable dt = DataAccess.ExeStoredNonToDataTable("usp_ProductSelectList");
            return dt;
        }

        public static DataTable GetMostViewList()
        {
            DataTable dt = DataAccess.ExeStoredNonToDataTable("usp_ProductSelectMostViewedList");
            return dt;
        }

        /// <summary>
        /// Lấy product có khuyến mại
        /// </summary>
        /// <returns></returns>
        public static DataTable GetPromotionProduct()
        {
            DataTable dt = DataAccess.ExeStoredNonToDataTable("usp_ProductSelectBonus");
            return dt;
        }

        /// <summary>
        /// lấy list product có khuyến mại
        /// </summary>
        /// <returns></returns>
        public static DataTable GetPromotionProductList()
        {
            DataTable dt = DataAccess.ExeStoredNonToDataTable("usp_ProductSelectBonusList");
            return dt;
        }

        /// <summary>
        /// Lấy product theo section =2 Electronic
        /// </summary>
        /// <returns></returns>
        public static DataTable GetElectronicProduct()
        {
            DataTable dt = DataAccess.ExeStoredNonToDataTable("usp_ProductSelectElectronic");
            return dt;
        }

        /// <summary>
        /// Lấy product theo section =7 phone
        /// </summary>
        /// <returns></returns>
        public static DataTable GetSmartPhoneProduct()
        {
            DataTable dt = DataAccess.ExeStoredNonToDataTable("usp_ProductSelectSmartPhone");
            return dt;
        }

        /// <summary>
        /// Get Menu
        /// </summary>
        /// <returns></returns>
        public static DataTable GetSection()
        {
            DataTable dt = DataAccess.ExeStoredNonToDataTable("usp_SectionSelectAll");
            return dt;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static DataTable GetCategoryBySection(Category category)
        {
            DataTable dt = DataAccess.ExeStoredWithParamToDataTable(
                "usp_CategorySelectBySectionId", "@SectionId", category.SectionId);
            return dt;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static DataTable GetProductBySection(Product product)
        {
            DataTable dt = DataAccess.ExeStoredWithParamToDataTable(
                "usp_ProductSelectBySection", "@SectionId", product.SectionId);
            return dt;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="category"></param>
        /// <param name="section"></param>
        /// <returns></returns>
        public static DataTable GetProductByCategory(Category category, Section section)
        {
            DataTable dt = DataAccess.ExeStoredWithParamToDataTable(
                "usp_SelectProductByCategoryId", "@CategoryId", category.CategoryId, "@SectionId", section.SectionId);
            return dt;
        }

        /// <summary>
        /// Lấy section theo id
        /// </summary>
        /// <returns></returns>
        public static DataTable GetSectionById(Section section)
        {
            DataTable dt = DataAccess.ExeStoredWithParamToDataTable(
                "usp_SelectSectionNameById", "@SectionId", section.SectionId);
            return dt;
        }

        /// <summary>
        /// Lấy Category theo id
        /// </summary>
        /// <returns></returns>
        public static DataTable GetCategoryById(Category category)
        {
            DataTable dt = DataAccess.ExeStoredWithParamToDataTable(
                "usp_SelectCategoryNameById", "@CategoryId", category.CategoryId);
            return dt;
        }

        /// <summary>
        /// Lấy Product theo id
        /// </summary>
        /// <returns></returns>
        public static DataTable GetProductById(Product product)
        {
            DataTable dt = DataAccess.ExeStoredWithParamToDataTable(
                "usp_ProductSelectById", "@ProductId", product.ProductId);
            return dt;
        }

        /// <summary>
        /// Lấy chi tiết Product theo id
        /// </summary>
        /// <returns></returns>
        public static DataTable GetProductDetailById(Product product)
        {
            DataTable dt = DataAccess.ExeStoredWithParamToDataTable(
                "usp_ProductDetailSelectById", "@ProductId", product.ProductId);
            return dt;
        }

        /// <summary>
        /// update visited
        /// </summary>
        /// <param name="product"></param>
        public static void UpdateVisited(Product product)
        {
            DataAccess.ExeStoredWithParamNon("usp_UpdateProductVisited", "@ProductId", product.ProductId);
        }

        public static DataTable SearchProductAll(string value)
        {
            return DataAccess.ExeStoredWithParamToDataTable("usp_SearchProductAll", "@searchValue", value);
        }
    }
}